home *** CD-ROM | disk | FTP | other *** search
- /*
- * Paragraph style dialog
- */
-
- # include "TransSkel.h"
-
- # include "MakeWrite.h"
-
- # define normalHilite 0
- # define dimHilite 255
-
- typedef enum /* paragraph style dialog item numbers */
- {
- paraOK = 1,
- paraCancel,
- paraEach,
- paraBlank,
- paraSmart,
- paraMText,
- paraPText,
- paraQText,
- paraLine1,
- paraLine2,
- pControlStaticText,
- lControlStaticText,
- markStaticText,
- periodStaticText,
- quoteStaticText,
- outlineUserItem
- };
-
-
- /*
- * Initialize paragraph style to default: blank lines and lines
- * beginning with whitespace initiate paragraphs, line joining
- * is smart, there's no explicit paragraph or page break marker.
- */
-
-
- static ParaStyle defStyle = { false, true, true };
- static Str255 defPeriodStr = "\p.!?";
- static Str255 defQuoteStr = { 5, '"', '\'', 0xd3, 0xd5, ')' };
-
-
- /*
- * Set the contents of a string using the contents of the 'STR '
- * resource whose id is passed as strResId.
- */
-
- static void
- ResSetString (short strResId, StringPtr str)
- {
- StringHandle hStr;
-
- hStr = GetString (strResId);
- HLock ((Handle) hStr);
- if ((*hStr)[0] > maxMarkLen)
- (*hStr)[0] = maxMarkLen;
- CopyString (*hStr, str);
- HUnlock ((Handle) hStr);
- ReleaseResource ((Handle) hStr);
- }
-
-
- void
- InitParaStyle (void)
- {
- paraStyle = defStyle;
- paraMark[0] = 0;
- pageMark[0] = 0;
- ResSetString (periodStrNum, periodStr);
- ResSetString (quoteStrNum, quoteStr);
- }
-
-
- static pascal void
- DoLine (DialogPtr dlog, short item)
- {
- Rect r;
-
- SkelGetDlogRect (dlog, item, &r);
- FrameRect (&r);
- }
-
-
- /*
- * Get the text of an item, and return true if it's different than
- * the current value
- */
-
- static Boolean
- CheckDText (DialogPtr dlog, short item, StringPtr str)
- {
- Str255 tmpStr;
- Boolean changed;
-
- SkelGetDlogStr (dlog, item, tmpStr);
- changed = (CompareString (str, tmpStr) != 0);
- CopyString (tmpStr, str);
- return (changed);
- }
-
-
- static void
- SetParaCheck (DialogPtr dlog, Boolean each, Boolean blank, Boolean smart)
- {
- SkelSetDlogCtlValue (dlog, paraEach, each);
- SkelSetDlogCtlValue (dlog, paraBlank, blank);
- SkelSetDlogCtlValue (dlog, paraSmart, smart);
- }
-
-
-
- void
- DoParaDialog (void)
- {
- ModalFilterProcPtr filter;
- DialogPtr dlog;
- GrafPtr tmpPort;
- short itemHit = 0;
- Boolean loop = true;
- short hilite;
- Boolean curEach, curBlank, curSmart;
- Boolean changed;
- Str255 s;
-
- dlog = GetNewDialog (paraDlogNum, nil, (WindowPtr) -1L);
- if (dlog == (DialogPtr) nil)
- {
- SysBeep (1);
- return;
- }
-
- SkelPositionWindow (dlog, skelPositionOnParentDevice,
- FixRatio (1, 2), FixRatio (1, 5));
-
- GetPort (&tmpPort);
- SetPort (dlog);
-
- SkelSetDlogButtonOutliner (dlog, outlineUserItem);
-
- SetParaCheck (dlog, curEach = paraStyle.pEachLine,
- curBlank = paraStyle.pBlankLine,
- curSmart = paraStyle.pSmartJoin);
- SkelSetDlogStr (dlog, paraPText, periodStr);
- SkelSetDlogStr (dlog, paraQText, quoteStr);
- SkelSetDlogStr (dlog, paraMText, paraMark);
- SkelSetDlogProc (dlog, paraLine1, DoLine);
- SkelSetDlogProc (dlog, paraLine2, DoLine);
-
- ShowWindow (dlog);
- InitCursor ();
-
- while (loop)
- {
- filter = SkelDlogFilter (nil, true);
- SkelDlogCancelItem (paraCancel);
- ModalDialog (filter, &itemHit);
- SkelRmveDlogFilter ();
-
- switch (itemHit)
- {
-
- case paraOK:
- changed = (paraStyle.pEachLine != curEach);
- paraStyle.pEachLine = curEach;
-
- changed |= (paraStyle.pBlankLine != curBlank);
- paraStyle.pBlankLine = curBlank;
-
- changed |= (paraStyle.pSmartJoin != curSmart);
- paraStyle.pSmartJoin = curSmart;
-
- changed |= CheckDText (dlog, paraMText, paraMark);
- changed |= CheckDText (dlog, paraPText, periodStr);
- changed |= CheckDText (dlog, paraQText, quoteStr);
-
- if (changed)
- mapModified = true;
- loop = false;
- break;
-
- case paraCancel:
- loop = false;
- break;
-
- case paraEach:
- curEach = !curEach;
- if (curEach)
- curBlank = false;
- break;
-
- case paraBlank:
- curBlank = !curBlank;
- if (curBlank)
- curEach = false;
- break;
-
- case paraSmart:
- curSmart = !curSmart;
- break;
-
- }
- SetParaCheck (dlog, curEach, curBlank, curSmart);
-
- /*
- * If smart join is selected but there aren't any sentence terminators,
- * disable the OK button.
- */
- SkelGetDlogStr (dlog, paraPText, s);
- hilite = (curSmart && s[0] == 0 ? dimHilite : normalHilite);
- if (SkelSetDlogCtlHilite (dlog, paraOK, hilite))
- SkelDrawButtonOutline (SkelGetDlogCtl (dlog, paraOK));
- }
- DisposeDialog (dlog);
- SetPort (tmpPort);
- }
-